<template>
	<view class="page" :data-theme="theme" :style="{height:winHeight + 'px'}">
		<simple :showSlide="showSlide" ref="classFive"></simple>
	</view>
</template>
<script>
	import simple from './components/simple';
	import {
		getShare
	} from '@/api/public.js';
	import {
		mapGetters
	} from 'vuex';
	import {
		loginMobile,
		getUserInfo
	} from "@/api/user";
	import home from '@/components/home/index.vue';
	import animationType from '@/utils/animationType.js';
	const app = getApp();
	export default {
		data() {
			return {
				currentPage: 'one',
				theme: app.globalData.theme,
				showSlide: true,
				winHeight: '',
				configApi: {}, //分享类容配置
			}
		},
		computed: mapGetters(['isLogin', 'uid']),
		onLoad() {
			let that = this;
			let config = that.$Cache.getItem('categoryConfig');
			// that.showSlide = config.isShowCategory == 'true' ? true : false;
			switch (config.categoryConfig) {
				case '1':
					that.$set(that, 'currentPage', 'one');
					uni.showTabBar()
					break;
				case '2':
					that.$set(that, 'currentPage', 'two');
					uni.showTabBar()
					break;
				case '3':
					that.$set(that, 'currentPage', 'three');
					uni.hideTabBar()
					break;
				case '4':
					that.$set(that, 'currentPage', 'four');
					uni.hideTabBar()
					break;
			}
			uni.getSystemInfo({
				success: function(res) {
					that.winHeight = res.windowHeight;
				}
			});
			// #ifdef H5
			that.shareApi();
			// #endif
		},
		onShow() {
			switch (this.currentPage) {
				case 'one':
					uni.showTabBar()
					break;
				case 'two':
					uni.showTabBar()
					break;
				case 'three':
					uni.hideTabBar()
					setTimeout(() => {
						if (this.isLogin) {
							//登录的情况下获取模板3,4的购物车商品数量和列表
							this.$refs.classThree.getCartNum();
							this.$refs.classThree.getCartLists(1);
						}
					}, 500)
					break;
				case 'four':
					uni.hideTabBar()
					setTimeout(() => {
						if (this.isLogin) {
							this.$refs.classFour.getCartNum();
							this.$refs.classFour.getCartLists(1);
						}
					}, 500)
					break;
			}
		},
		components: {
			simple
		},
		mounted: function() {
			let that = this;

			let locatiojUrl = window.location.href;
			//let locatiojUrl = 'http://10.10.6.34:8080/qz/?phone=13012562102';

			//console.log('@@##!!', window.location.href);


			if (locatiojUrl.indexOf('?') != -1) {
				let phone = decodeURI(that.jqueryUrl(locatiojUrl).phone);

				loginMobile({
						phone: phone,
						captcha: '000000',
						spread_spid: 10001
					})
					.then(res => {
						let data = res.data;
						let newTime = Math.round(new Date() / 1000);
						that.$store.commit("LOGIN", {
							'token': res.data.token
						});
						that.getUserInfo(data);
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
					});
			}
			let platform = uni.getSystemInfoSync().platform; //手机类型
			//console.log('1122  ' + window.android || window.webkit)
			//console.log('1122  ' + platform)

			// uni.navigateTo({
			// 	animationType: animationType.type,
			// 	animationDuration: animationType.duration,
			// 	url: '/pages/app_member/index',
			// 	//url: '/pages/app_orderCourse/index',
			// })
		},
		methods: {
			getUserInfo(data) {
				let that = this;
				that.$store.commit("SETUID", data.uid);
				getUserInfo().then(res => {
					that.$store.commit("UPDATE_USERINFO", res.data);
				})
			},
			jqueryUrl(url) {
				let arr = url.split('?');
				let params = arr[1].split('&');
				let obj = {};
				for (let i = 0; i < params.length; i++) {
					let param = params[i].split('=');
					obj[param[0]] = param[1];
				}
				return obj;
			},
			shareApi: function() {
				getShare().then(res => {
					this.$set(this, 'configApi', res.data);
					// #ifdef H5
					this.setOpenShare(res.data);
					// #endif
				})
			},
			// 微信分享；
			setOpenShare: function(data) {
				let that = this;
				if (that.$wechat.isWeixin()) {
					let configAppMessage = {
						desc: data.synopsis,
						title: data.title,
						link: location.href,
						imgUrl: data.img
					};
					that.$wechat.wechatEvevt(["updateAppMessageShareData", "updateTimelineShareData"],
						configAppMessage);
				}
			},
		},
		onReachBottom() {
			if (this.currentPage == 'two') {
				this.$refs.classTwo.getProductList();
			}
			if (this.currentPage == 'three') {
				this.$refs.classThree.productslist();
			}
			if (this.currentPage == 'four') {
				this.$refs.classFour.productslist();
			}
		}
	}
</script>
<style lang="scss">
	.page {
		background: #fff;
		// overflow-y: auto;
	}
</style>